<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%><%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
$(document).ready(function() { 
        $("#galleriesTable").tablesorter({ 
            // pass the headers argument and assing a object 
            headers: { 
                // assign the first column (we start counting zero) 
                0: { 
                    // disable it by setting the property sorter to false 
                    sorter: false
                }
            }
        }); 
    } 
); 

function submitDelete() {

	if ($("[name=selectedGalleries]:checkbox:checked").length < 1) {
		alert('<s:text name="general.no.selection" />');
	} else if (confirm('<s:text name="general.delete.confirm" />')){
	
		$('#galleriesForm').find('#mode').val('DEL');
		$('#galleriesForm').submit();	 
		
	}
}
</script> 
<div>
	<s:hidden name="mode" value="A"></s:hidden>
	<s:hidden name="galleryId"></s:hidden>
	<div class="title">
		<s:text name="gallery.list.title" />
	</div>
	<s:if test="%{gallery != null}">
		<div class="container">
			<table>
				<tr>
					<td class="tdLabel"><s:text name="gallery.name" />:</td>
					<td><s:property value="gallery.name"/></td>
				</tr>
				<tr>
					<td class="tdLabel"><s:text name="gallery.description" />:</td>
					<td><s:property value="gallery.description"/></td>
				</tr>
				<tr>
					<td class="tdLabel"><s:text name="gallery.parent.name" />:</td>
					<td>
						<s:if test="%{gallery.parent != null}" >
							<a href="Galleries.action?mode=L&galleryId=<s:property value="gallery.parent.id"/>" >
								<s:property value="gallery.parent.name"/>
							</a>
						</s:if>
						<s:else>
							<a href="Galleries.action?mode=L&galleryId=-1">
								<s:text name="general.root" />
							</a>
						</s:else>
					</td>
				</tr>
				<tr>
					<td class="tdLabel"><s:text name="gallery.public" />:</td>
					<td>
						<s:if test="%{gallery.isPublicAccess()}" >
							<s:text name="general.yes" />
						</s:if>
						<s:else>
							<s:text name="general.no" />
						</s:else>
					</td>
				</tr>
			</table>
		</div>
	</s:if>

	
	<div class="container">

		<form id="galleriesForm" action="Galleries.action" method="post">
			<s:if test="%{galleries.size() > 0 || query != ''}">
				<div class="container">
					<s:hidden name="mode" value="L"></s:hidden>
					<s:hidden name="galleryId"></s:hidden>
					<s:text name="gallery.name" />
					<input type="text" name="query" value="<s:property value="query"/>"/>
					<button class="action" type="submit" name="search"><s:text name="gallery.list.search" /></button>			
					<s:if test="%{query != ''}" >
						<button class="action" type="submit" name="search" onclick="javascript: return submitClear(this.form);"><s:text name="gallery.list.clear" /></button>			
					</s:if>
				</div>
			</s:if>
			
			<s:if test="%{galleries.size() > 0}">
				<table id="galleriesTable" class="tablesorter" > 
					<thead> 
						<tr> 
						    <th class="checkboxes">&nbsp;</th> 
	                        <th><s:text name="gallery.name" /></th> 
	                        <th><s:text name="gallery.description" /></th>
						    <th><s:text name="gallery.public" /></th>
						</tr> 
						</thead>
					<tbody>
					<s:iterator id="gallery" value="galleries">
						<tr>
						   <td><input type="checkbox" name="selectedGalleries" 
	                                value="<s:property id="gallery" value="id"/>"></td>
							<td>
								<a href="Galleries.action?mode=L&galleryId=<s:property id="gallery" value="id"/>"> 
									<s:property id="gallery" value="name" default=" -none- "/> 
								</a>
							</td>
							<td>
								<s:property id="gallery" value="description" default=" -none- "/>
							</td>
							<td>
								<s:if test="%{#gallery.publicAccess}" >
									<s:text name="general.yes" />
								</s:if>
								<s:else>
									<s:text name="general.no" />
								</s:else>
							</td>
						</tr>
					</s:iterator>
					</tbody>
				</table>
			</s:if>
			<s:else>
				<s:if test="%{query != ''}" >
					<s:text name="gallery.list.no.search.results"></s:text>
				</s:if>
				<s:else>
					<s:text name="gallery.list.no.child.galleries"></s:text>
				</s:else>
			</s:else>
		</form>
	</div>
	
	<div class="container">
        <a class="action" href="../galleries/Galleries.action?mode=AP&galleryId=<s:property value="galleryId"/>">
          <s:text name="gallery.list.add" />
        </a>&nbsp;
        <s:if test="%{galleries.size() > 0}">
            <a class="action" href="javascript: submitDelete();">
              <s:text name="gallery.list.delete" />
            </a>&nbsp;
        </s:if>
        <s:if test="%{gallery != null}">
            <a class="action"  href="../galleries/Images.action?mode=L&galleryId=<s:property value="galleryId"/>"><s:text name="gallery.list.pictures" /></a>
            <s:if test="%{!gallery.isPublicAccess()}" >
                <a class="action" href="../galleries/Galleries.action?mode=MPu&galleryId=<s:property value="galleryId"/>"><s:text name="gallery.list.make.public" /></a>
            </s:if>
            <s:else>
                <a class="action" href="../galleries/Galleries.action?mode=MPr&galleryId=<s:property value="galleryId"/>"><s:text name="gallery.list.make.private" /></a>
                <a class="action" href="../galleries/Advertise.action?mode=ADV&galleryId=<s:property value="galleryId"/>"><s:text name="gallery.list.advertise" /></a>
            </s:else>
        </s:if>
    </div>  

	<s:if test="%{showUploadPictures}">
		<div class="container" style="height: 92px;" >
			<div style="float:left; width: 66%;">
				<s:text name="gallery.list.upload.title" />
					<s:form action="/galleries/GalleryUpload.action" method="POST" enctype="multipart/form-data">
						<s:hidden name="mode" value="UPLOAD"></s:hidden>
						<s:hidden name="galleryId"></s:hidden>
						<table border="0" cellpadding="3" cellspacing="0">
					      <tr>
					        <td>
					        	<s:file name="uploadedFile"  key="gallery.add.name" ></s:file>
					        </td>
					      </tr>
					      <tr>
					        <td>
					          <input class="action" type="submit" value="<s:text name="common.upload" />" />
					        </td>
					      </tr>
					    </table>
					</s:form>
				</div>
				<div style="float:left; width: 33%;">
					<s:text name="gallery.list.sync.message"/> <br />
					<a class="action" href="../galleries/FsSync.action?mode=VIEW&galleryId=<s:property value="galleryId"/>"><s:text name="common.start" /></a>&nbsp;
					<a class="action" href="#" onclick="javascript: alert('<s:text name="gallery.list.sync.help.text"/>'); return false;"><s:text name="gallery.list.sync.help"/></a>
					
				</div>
			</div>
		</s:if>
	</div>